package com.wanho.java157.controller;


import com.wanho.java157.Employee;
import com.wanho.java157.Orders;
import com.wanho.java157.result.R;
import com.wanho.java157.vo.EmployeeVo;
import com.wanho.java157.vo.OrdersVo;
import com.wanho.java158.EmployeeService;
import com.wanho.java158.OrdersService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/core/employee")
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;
//管理员显示页面
    @GetMapping("/index/{employeeId}")
    public R listAll(@PathVariable String employeeId){
        List<EmployeeVo> employeeId1 = employeeService.select("employeeId");
        return R.ok().data("list", employeeId1).message("获取列表成功");
    }

    @DeleteMapping("/remove/{employeeId}")
    public R removeById(
            @PathVariable Integer employeeId) {
        boolean result = employeeService.delete(employeeId);
        if (result) {
            return R.ok().message("删除成功");
        } else {
            return R.error().message("删除失败");
        }
    }


    @PutMapping("/update")
    public R updateById(
            @RequestBody EmployeeVo employeeVo){
        boolean result = employeeService.update(employeeVo) ;
        if(result){
            return R.ok().message("更新成功");
        }else{
            return R.error().message("更新失败");
        }
    }

    @PostMapping("/add")
    public R add(
            @RequestBody EmployeeVo employeeVo){
        boolean result = employeeService.add(employeeVo) ;
        if(result){
            return R.ok().message("增加成功");
        }else{
            return R.error().message("增加失败");
        }
    }


}
